package P17;

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author DJ同学
 * @Date 2021/2/28 0:28
 * @Version 1.0
 * @Name 电话号码中的字母组合
 * @Problem https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number/
 */
public class Solution {

    private List<String> res = new ArrayList<>();
    private List<String> map = new ArrayList<>();
    private char[] one;
    public List<String> letterCombinations(String digits) {
            if(digits==null||digits.length()==0){
                return res;
            }
            map.add("");
            map.add("");
            map.add("abc");
            map.add("def");
            map.add("ghi");
            map.add("jkl");
            map.add("mno");
            map.add("pqrs");
            map.add("tuv");
            map.add("wxyz");
            one = new char[digits.length()];
            dfs(digits,0,digits.length());
            return res;
    }

    private void dfs(String digits, int step, int max) {
        //出口
        if(step==max){
            String s="";
            for(char c:one){
                s+=c;
            }
            res.add(s);
            return ;
        }
        //获得当前整数
        int num = digits.charAt(step)-'0';
        for(int i = 0;i<map.get(num).length();i++){
            one[step] = map.get(num).charAt(i);
            dfs(digits,step+1,max);
        }
    }

    @Test
    public void test(){
        List<String> strings = letterCombinations("23");
        return ;
    }
}
